#Boa:Frame:CadastroUsuario

import wx
import Frame_JanelaPrincipal
from Class_Endereco import *
from Class_Contato import *
from Class_Usuario import *
from Class_GerenciadorUsuario import *

def create(parent):
    return CadastroUsuario(parent)

[wxID_CADASTROUSUARIO, wxID_CADASTROUSUARIOCADASTRAR, 
 wxID_CADASTROUSUARIOCANCELAR, wxID_CADASTROUSUARIODATEPICKERCTRL1, 
 wxID_CADASTROUSUARIOPANEL1, wxID_CADASTROUSUARIOSTATICBOX1, 
 wxID_CADASTROUSUARIOSTATICBOX2, wxID_CADASTROUSUARIOSTATICBOX3, 
 wxID_CADASTROUSUARIOSTATICBOX4, wxID_CADASTROUSUARIOSTATICTEXT1, 
 wxID_CADASTROUSUARIOSTATICTEXT10, wxID_CADASTROUSUARIOSTATICTEXT11, 
 wxID_CADASTROUSUARIOSTATICTEXT12, wxID_CADASTROUSUARIOSTATICTEXT13, 
 wxID_CADASTROUSUARIOSTATICTEXT14, wxID_CADASTROUSUARIOSTATICTEXT15, 
 wxID_CADASTROUSUARIOSTATICTEXT16, wxID_CADASTROUSUARIOSTATICTEXT17, 
 wxID_CADASTROUSUARIOSTATICTEXT18, wxID_CADASTROUSUARIOSTATICTEXT19, 
 wxID_CADASTROUSUARIOSTATICTEXT2, wxID_CADASTROUSUARIOSTATICTEXT3, 
 wxID_CADASTROUSUARIOSTATICTEXT4, wxID_CADASTROUSUARIOSTATICTEXT5, 
 wxID_CADASTROUSUARIOSTATICTEXT6, wxID_CADASTROUSUARIOSTATICTEXT7, 
 wxID_CADASTROUSUARIOSTATICTEXT8, wxID_CADASTROUSUARIOSTATICTEXT9, 
 wxID_CADASTROUSUARIOTEXTCTRL1, wxID_CADASTROUSUARIOTEXTCTRL10, 
 wxID_CADASTROUSUARIOTEXTCTRL11, wxID_CADASTROUSUARIOTEXTCTRL12, 
 wxID_CADASTROUSUARIOTEXTCTRL13, wxID_CADASTROUSUARIOTEXTCTRL14, 
 wxID_CADASTROUSUARIOTEXTCTRL15, wxID_CADASTROUSUARIOTEXTCTRL16, 
 wxID_CADASTROUSUARIOTEXTCTRL17, wxID_CADASTROUSUARIOTEXTCTRL2, 
 wxID_CADASTROUSUARIOTEXTCTRL3, wxID_CADASTROUSUARIOTEXTCTRL4, 
 wxID_CADASTROUSUARIOTEXTCTRL5, wxID_CADASTROUSUARIOTEXTCTRL6, 
 wxID_CADASTROUSUARIOTEXTCTRL7, wxID_CADASTROUSUARIOTEXTCTRL8, 
 wxID_CADASTROUSUARIOTEXTCTRL9, wxID_CADASTROUSUARIOWINDOW1, 
 wxID_CADASTROUSUARIOWINDOW2, wxID_CADASTROUSUARIOWINDOW3, 
 wxID_CADASTROUSUARIOWINDOW4, wxID_CADASTROUSUARIOWINDOW5, 
] = [wx.NewId() for _init_ctrls in range(50)]

class CadastroUsuario(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_CADASTROUSUARIO,
              name=u'CadastroUsuario', parent=prnt, pos=wx.Point(536, 43),
              size=wx.Size(662, 691), style=wx.DEFAULT_FRAME_STYLE,
              title='Frame1')
        self.SetClientSize(wx.Size(654, 658))
        self.Center(wx.BOTH)

        self.panel1 = wx.Panel(id=wxID_CADASTROUSUARIOPANEL1, name='panel1',
              parent=self, pos=wx.Point(0, 0), size=wx.Size(654, 658),
              style=wx.TAB_TRAVERSAL)

        self.window1 = wx.Window(id=wxID_CADASTROUSUARIOWINDOW1, name='window1',
              parent=self.panel1, pos=wx.Point(40, 40), size=wx.Size(304, 184),
              style=wx.TAB_TRAVERSAL)

        self.textCtrl1 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL1,
              name='textCtrl1', parent=self.window1, pos=wx.Point(168, 32),
              size=wx.Size(100, 21), style=0, value=u'')

        self.textCtrl2 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL2,
              name='textCtrl2', parent=self.window1, pos=wx.Point(168, 80),
              size=wx.Size(100, 21), style=0, value=u'')

        self.datePickerCtrl1 = wx.DatePickerCtrl(id=wxID_CADASTROUSUARIODATEPICKERCTRL1,
              name='datePickerCtrl1', parent=self.window1, pos=wx.Point(168,
              128), size=wx.Size(96, 21), style=wx.DP_SHOWCENTURY)

        self.staticBox1 = wx.StaticBox(id=wxID_CADASTROUSUARIOSTATICBOX1,
              label=u'Dados Pessoais', name='staticBox1', parent=self.window1,
              pos=wx.Point(8, 8), size=wx.Size(280, 160), style=0)

        self.staticText1 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT1,
              label=u'Nome*', name='staticText1', parent=self.window1,
              pos=wx.Point(112, 32), size=wx.Size(33, 13), style=0)

        self.staticText2 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT2,
              label=u'Sobrenome*', name='staticText2', parent=self.window1,
              pos=wx.Point(88, 80), size=wx.Size(60, 13), style=0)

        self.staticText3 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT3,
              label=u'Data de Nascimento*', name='staticText3',
              parent=self.window1, pos=wx.Point(48, 128), size=wx.Size(102, 13),
              style=0)

        self.window2 = wx.Window(id=wxID_CADASTROUSUARIOWINDOW2, name='window2',
              parent=self.panel1, pos=wx.Point(40, 248), size=wx.Size(296, 376),
              style=wx.TAB_TRAVERSAL)

        self.staticBox2 = wx.StaticBox(id=wxID_CADASTROUSUARIOSTATICBOX2,
              label=u'Endere\xe7o', name='staticBox2', parent=self.window2,
              pos=wx.Point(32, 8), size=wx.Size(256, 360), style=0)

        self.textCtrl3 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL3,
              name='textCtrl3', parent=self.window2, pos=wx.Point(160, 40),
              size=wx.Size(100, 21), style=0, value=u'')

        self.textCtrl4 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL4,
              name='textCtrl4', parent=self.window2, pos=wx.Point(160, 80),
              size=wx.Size(100, 21), style=0, value=u'')

        self.textCtrl5 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL5,
              name='textCtrl5', parent=self.window2, pos=wx.Point(160, 120),
              size=wx.Size(100, 21), style=0, value=u'')

        self.textCtrl6 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL6,
              name='textCtrl6', parent=self.window2, pos=wx.Point(160, 160),
              size=wx.Size(100, 21), style=0, value=u'')

        self.textCtrl7 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL7,
              name='textCtrl7', parent=self.window2, pos=wx.Point(160, 200),
              size=wx.Size(100, 21), style=0, value=u'')

        self.textCtrl8 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL8,
              name='textCtrl8', parent=self.window2, pos=wx.Point(160, 240),
              size=wx.Size(100, 21), style=0, value=u'')

        self.textCtrl9 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL9,
              name='textCtrl9', parent=self.window2, pos=wx.Point(160, 280),
              size=wx.Size(100, 21), style=0, value=u'')

        self.textCtrl10 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL10,
              name='textCtrl10', parent=self.window2, pos=wx.Point(160, 320),
              size=wx.Size(100, 21), style=0, value=u'')

        self.staticText4 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT4,
              label=u'CEP*', name=u'staticText4', parent=self.window2,
              pos=wx.Point(104, 40), size=wx.Size(25, 13), style=0)

        self.staticText5 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT5,
              label=u'N\xfamero', name='staticText5', parent=self.window2,
              pos=wx.Point(88, 120), size=wx.Size(37, 13), style=0)

        self.staticText6 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT6,
              label=u'Logradouro*', name='staticText6', parent=self.window2,
              pos=wx.Point(72, 80), size=wx.Size(61, 13), style=0)

        self.staticText7 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT7,
              label=u'Complemento', name='staticText7', parent=self.window2,
              pos=wx.Point(64, 160), size=wx.Size(65, 13), style=0)

        self.staticText8 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT8,
              label=u'Bairro*', name='staticText8', parent=self.window2,
              pos=wx.Point(104, 200), size=wx.Size(34, 13), style=0)

        self.staticText9 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT9,
              label=u'Cidade*', name='staticText9', parent=self.window2,
              pos=wx.Point(104, 240), size=wx.Size(39, 13), style=0)

        self.staticText10 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT10,
              label=u'Estado*', name='staticText10', parent=self.window2,
              pos=wx.Point(104, 280), size=wx.Size(39, 13), style=0)

        self.staticText11 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT11,
              label=u'Pa\xeds*', name='staticText11', parent=self.window2,
              pos=wx.Point(120, 320), size=wx.Size(25, 13), style=0)

        self.window3 = wx.Window(id=wxID_CADASTROUSUARIOWINDOW3, name='window3',
              parent=self.panel1, pos=wx.Point(384, 48), size=wx.Size(256, 168),
              style=wx.TAB_TRAVERSAL)

        self.textCtrl11 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL11,
              name='textCtrl11', parent=self.window3, pos=wx.Point(136, 32),
              size=wx.Size(100, 21), style=0, value=u'')

        self.textCtrl12 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL12,
              name='textCtrl12', parent=self.window3, pos=wx.Point(136, 72),
              size=wx.Size(100, 21), style=wx.TE_PASSWORD, value=u'')

        self.staticText12 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT12,
              label=u'Login*', name='staticText12', parent=self.window3,
              pos=wx.Point(48, 32), size=wx.Size(31, 13), style=0)

        self.staticText13 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT13,
              label=u'Senha*', name='staticText13', parent=self.window3,
              pos=wx.Point(48, 72), size=wx.Size(36, 13), style=0)

        self.staticBox3 = wx.StaticBox(id=wxID_CADASTROUSUARIOSTATICBOX3,
              label=u'Acesso', name='staticBox3', parent=self.window3,
              pos=wx.Point(8, 8), size=wx.Size(240, 144), style=0)

        self.window4 = wx.Window(id=wxID_CADASTROUSUARIOWINDOW4, name='window4',
              parent=self.panel1, pos=wx.Point(392, 224), size=wx.Size(232,
              232), style=wx.TAB_TRAVERSAL)

        self.textCtrl13 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL13,
              name='textCtrl13', parent=self.window4, pos=wx.Point(104, 40),
              size=wx.Size(100, 21), style=0, value=u'')

        self.textCtrl14 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL14,
              name='textCtrl14', parent=self.window4, pos=wx.Point(104, 88),
              size=wx.Size(100, 21), style=0, value=u'')

        self.textCtrl15 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL15,
              name='textCtrl15', parent=self.window4, pos=wx.Point(104, 136),
              size=wx.Size(100, 21), style=0, value=u'')

        self.textCtrl16 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL16,
              name='textCtrl16', parent=self.window4, pos=wx.Point(104, 184),
              size=wx.Size(100, 21), style=0, value=u'')

        self.staticText14 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT14,
              label=u'Email*', name='staticText14', parent=self.window4,
              pos=wx.Point(48, 40), size=wx.Size(30, 13), style=0)

        self.staticText15 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT15,
              label=u'Telefone 1*', name='staticText15', parent=self.window4,
              pos=wx.Point(24, 88), size=wx.Size(57, 13), style=0)

        self.staticText16 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT16,
              label=u'Telefone 2', name='staticText16', parent=self.window4,
              pos=wx.Point(32, 136), size=wx.Size(51, 13), style=0)

        self.staticText17 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT17,
              label=u'Telefone 3', name='staticText17', parent=self.window4,
              pos=wx.Point(32, 184), size=wx.Size(51, 13), style=0)

        self.staticBox4 = wx.StaticBox(id=wxID_CADASTROUSUARIOSTATICBOX4,
              label=u'Contato', name='staticBox4', parent=self.window4,
              pos=wx.Point(8, 8), size=wx.Size(216, 216), style=0)

        self.window5 = wx.Window(id=wxID_CADASTROUSUARIOWINDOW5, name='window5',
              parent=self.panel1, pos=wx.Point(392, 480), size=wx.Size(232,
              136), style=0)

        self.Cadastrar = wx.Button(id=wxID_CADASTROUSUARIOCADASTRAR,
              label=u'Cadastrar', name=u'Cadastrar', parent=self.window5,
              pos=wx.Point(59, 24), size=wx.Size(114, 32), style=0)
        self.Cadastrar.Center(wx.HORIZONTAL)
        self.Cadastrar.Bind(wx.EVT_BUTTON, self.OnCadastrarButton,
              id=wxID_CADASTROUSUARIOCADASTRAR)

        self.Cancelar = wx.Button(id=wxID_CADASTROUSUARIOCANCELAR,
              label=u'Cancelar', name=u'Cancelar', parent=self.window5,
              pos=wx.Point(59, 80), size=wx.Size(114, 32), style=0)
        self.Cancelar.Center(wx.HORIZONTAL)
        self.Cancelar.Bind(wx.EVT_BUTTON, self.OnCancelarButton,
              id=wxID_CADASTROUSUARIOCANCELAR)

        self.textCtrl17 = wx.TextCtrl(id=wxID_CADASTROUSUARIOTEXTCTRL17,
              name='textCtrl17', parent=self.window3, pos=wx.Point(136, 112),
              size=wx.Size(100, 21), style=wx.TE_PASSWORD, value=u'')
        self.textCtrl17.Bind(wx.EVT_KILL_FOCUS, self.OnTextCtrl17KillFocus)

        self.staticText18 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT18,
              label=u'Confirma\xe7\xe3o senha*', name='staticText18',
              parent=self.window3, pos=wx.Point(24, 112), size=wx.Size(98, 13),
              style=0)

        self.staticText19 = wx.StaticText(id=wxID_CADASTROUSUARIOSTATICTEXT19,
              label=u'(*) Informa\xe7\xf5es Essenciais', name='staticText19',
              parent=self.panel1, pos=wx.Point(64, 632), size=wx.Size(128, 13),
              style=0)

    def __init__(self, parent):
        self._init_ctrls(parent)

    def OnCadastrarButton(self, event):
        Logradouro = self.textCtrl4.GetValue()
        Numero = self.textCtrl5.GetValue()
        Complemento = self.textCtrl6.GetValue()
        Bairro = self.textCtrl7.GetValue()
        Cidade = self.textCtrl8.GetValue()
        Estado = self.textCtrl9.GetValue()
        Pais = self.textCtrl10.GetValue()
        CEP = self.textCtrl3.GetValue()
        endereco = Endereco(Logradouro, Numero, Complemento, Bairro, Cidade, Estado, Pais, CEP)
        
        Telefone1 = self.textCtrl14.GetValue()
        Telefone2 = self.textCtrl15.GetValue()
        Telefone3 = self.textCtrl16.GetValue()
        Email = self.textCtrl13.GetValue()
        contato = Contato(Telefone1, Telefone2, Telefone3, Email)
        
        Nome = self.textCtrl1.GetValue()
        Sobrenome = self.textCtrl2.GetValue()
        DataNasc = (self.datePickerCtrl1.GetValue())
        Login = self.textCtrl11.GetValue()
        Senha = self.textCtrl12.GetValue()
        
        
        Ano = DataNasc.GetYear()
        Mes = DataNasc.GetMonth()
        Dia = DataNasc.GetDay()
        Data = '%s-%s-%s'%(Ano, Mes, Dia)

        
        usuario = Usuario(Nome, Sobrenome, Data, Login, Senha, contato, endereco)
        
        
        g = GerenciadorUsuario()
        confirmacao = g.Cadastrar(usuario)
        if confirmacao == True:
            m = "Cadastro Realizado com Sucesso!"
            t = "Cadastro de Usuario"
            wx.MessageBox(m,t,wx.OK)
            self.Close()
        else:
            m = "Cadastro nao foi efetuado!"
            t = "Cadastro de Usuario"
            wx.MessageBox(m,t,wx.ICON_ERROR)
        
        
        
    def OnCancelarButton(self, event):
        self.Close()
        self.tela = Frame_JanelaPrincipal.create(None)
        self.tela.Show()

    def OnTextCtrl17KillFocus(self, event):
        if self.textCtrl12.GetValue() <> self.textCtrl17.GetValue():
            m = "senha e confirmacao de senha nao conferem, Favor digitar a senha novamente!"
            t = "Senhas diferentes"
            wx.MessageBox(m,t,wx.ICON_ERROR)
            self.textCtrl12.SetValue('')
            self.textCtrl17.SetValue('')
            self.textCtrl12.SetFocus()
            


            
